// 基于准备好的dom，初始化echarts实例
let myChart = echarts.init(document.getElementById('main'));

// 指定图表的配置项和数据
let option = {
    tooltip: {
        trigger: 'axis',
        axisPointer: {            // 坐标轴指示器，坐标轴触发有效
            type: 'shadow'        // 默认为直线，可选为：'line' | 'shadow'
        }
    },
    legend: {
        data: ['博士点', '硕士点', '国家重点实验室', '重点学科']
    },
    grid: {
        left: '3%',
        right: '4%',
        bottom: '3%',
        containLabel: true
    },
    xAxis: {
        type: 'value'
    },
    yAxis: {
        // 学校列表
        type: 'category',
        data: null
    },
    series: [
        {
            name: '博士点',
            type: 'bar',
            stack: '总量',
            label: {
                show: true,
                position: 'insideRight'
            },
            data: null
        },
        {
            name: '硕士点',
            type: 'bar',
            stack: '总量',
            label: {
                show: true,
                position: 'insideRight'
            },
            data: null
        },
        {
            name: '国家重点实验室',
            type: 'bar',
            stack: '总量',
            label: {
                show: true,
                position: 'insideRight'
            },
            data: null
        },
        {
            name: '重点学科',
            type: 'bar',
            stack: '总量',
            label: {
                show: true,
                position: 'insideRight'
            },
            data: null
        }
    ]
};

let school_list = new Array();
let doctor_number = new Array();
let master_number = new Array();
let key_discipline_number = new Array();
let key_laboratory_number = new Array();

$.ajax({
    type: "GET",
    url: '/schoolRank/total',
    success: function (res) {
        for (let i = 0; i < res.length; i++) {
            console.log(res);
            school_list.push(res[i].schoolName);
            doctor_number.push(res[i].doctor);
            master_number.push(res[i].master);
            key_discipline_number.push(res[i].keyDiscipline);
            key_laboratory_number.push(res[i].keyLaboratory);
        }

        option.yAxis.data = school_list;
        option.series[0].data = doctor_number;
        option.series[1].data = master_number;
        option.series[2].data = key_discipline_number;
        option.series[3].data = key_laboratory_number;

        // 使用刚指定的配置项和数据显示图表。
        myChart.setOption(option);
    },
    cache: false
});